package org.budo.graph.entity;

import java.io.Serializable;

import lombok.Getter;
import lombok.Setter;

/**
 * @author lmw
 */
@Getter
@Setter
public class DubboProvider implements Serializable {
    private static final long serialVersionUID = 1293765201279569407L;

    private String host = "";

    private Integer port = 0;

    private String applicationName = "";

    private String processName = "";

    /**
     * 目标机器系统当前时间
     */
    private String systemTime = "";

    private String startTime = "";

    private String buildTime = "";

    private Integer druidActiveCount = 0;

    private Integer druidMaxActive = 0;

    private Integer redisNumActive = 0;

    private Integer redisMaxTotal = 0;

    private String sourceCodeVersion = "NoCodeVersion";

    private Long maxMemory = -1L;

    private Long totalMemory = -1L;

    private Long freeMemory = -1L;

    public String getApplicationNameNoNull() {
        String _applicationName = this.getApplicationName();
        return null == _applicationName ? "" : _applicationName;
    }

    /**
     * 列表
     */
    public String toSimpleString() {
        String str = this.getHost() + ":" + this.getPort() //
                + " " + this.getProcessName() //
                + " " + this.getApplicationName() //
                + " " + this.getStartTime();

        Integer dbActive = this.getDruidActiveCount();
        Integer dbMax = this.getDruidMaxActive();
        if (null != dbActive && dbActive > 0) {
            str += " <b>" + dbActive + "/" + dbMax + "</b>";
        } else {
            str += " " + dbActive + "/" + dbMax;
        }

        Integer redisMax = this.getRedisMaxTotal();
        Integer redisActive = this.getRedisNumActive();
        if (null != redisActive && redisActive > 0) {
            str += " <b>" + redisActive + "/" + redisMax + "</b>";
        } else {
            str += " " + redisActive + "/" + redisMax;
        }

        return str;
    }

    /**
     * title
     */
    public String toFullString() {
        String str = this.getHost() + ":" + this.getPort() //
                + ", ProcessName=" + this.getProcessName() //
                + ", StartTime=" + this.getStartTime();

        str += ", DruidActiveCount=" + this.getDruidActiveCount();
        str += ", DruidMaxActive=" + this.getDruidMaxActive();

        str += ", RedisNumActive=" + this.getRedisNumActive();
        str += ", RedisMaxTotal=" + this.getRedisMaxTotal();

        str += ", SourceCodeVersion=" + this.getSourceCodeVersion();

        str += ", BuildTime=" + this.getBuildTime();
        str += ", systemTime=" + this.getSystemTime(); // 系统当前时间

        str += ", freeMemory=" + this.getFreeMemory();
        str += ", maxMemory=" + this.getMaxMemory();
        str += ", totalMemory=" + this.getTotalMemory();

        return str;
    }

    /**
     * 内页
     */
    public String toNameString() {
        String str = this.getProcessName();

        str += " " + this.getApplicationName();

        if ((null != this.getDruidActiveCount() && this.getDruidActiveCount() >= 0) //
                || (null != this.getDruidMaxActive() && this.getDruidMaxActive() >= 0)) {
            str += " " + this.getDruidActiveCount() + "/" + this.getDruidMaxActive();
        }

        if (null != this.getBuildTime()) {
            str += " " + this.getBuildTime();
        }

        return str;
    }

    @Override
    public String toString() {
        return super.toString() + " [host=" + host //
                + ", port=" + port //
                + ", applicationName=" + applicationName //
                + ", processName=" + processName //
                + ", systemTime=" + systemTime //
                + ", startTime=" + startTime //
                + ", buildTime=" + buildTime //
                + ", druidActiveCount=" + druidActiveCount //
                + ", druidMaxActive=" + druidMaxActive //
                + ", sourceCodeVersion=" + sourceCodeVersion //
                + ", maxMemory=" + maxMemory //
                + ", totalMemory=" + totalMemory //
                + ", freeMemory=" + freeMemory + "]";
    }
}